package com.example.demo.service;

import com.example.demo.entity.ProductEntity;
import com.example.demo.mapper.ProductMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductService {
    @Autowired
    ProductMapper productMapper;

    public List<ProductEntity> findAll(ProductEntity product) {
        return productMapper.findAll(product);
    }
    public boolean saveProduct(ProductEntity product) {
        if (product.getId() > 0) {  //有ID则为更新，否则为添加
            return productMapper.update(product);
        } else {
            return productMapper.insert(product);
        }
    }

    public boolean delProduct(Integer id) {
        return productMapper.delete(id);
    }

    public int getCount(ProductEntity product) {
        return productMapper.getCount(product);
    }

}
